<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>生产制作件清单创建</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>

                                <div class="form-group">
                                    <label for="query-specialId">类型</label>
                                    <select id="query-specialId" class="form-control" name="specialId">
                                        <option value="" selected>请选择</option>
                                        <option th:each="type : ${specialId}" th:value="${type.id}"
                                                th:text="${type.name}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部位</label>
                                    <input id="query-part" type="text" name="part" class="form-control"
                                           placeholder="请输入部分">
                                </div>

                                <div class="form-group">
                                    <label for="query-startTime">创建日期</label>
                                    <input id="query-startTime" type="text" class="form-control datepicker"
                                           name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>


                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                    <button type="button" class="btn btn-success" id="btn-receive"
                            onclick="openReleaseModal()"  shiro:hasPermission="tec:proProduc:edit" >
                        <span class="Bold">创建总图号</span>
                    </button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel" align="center">
                    添加生产总图号
                </h4>
            </div>
            <div class="modal-body">
                <form id="partForm" class="form-horizontal" role="form">
                    <input type="hidden" id="id" name="id">
                    <div class="form-group" id="DD">
                        <label class="col-sm-3 control-label no-padding-right">项目编号 ：</label>
                        <div class="col-sm-9">
                            <select id="sheetForm-proCode" style="width:420px" class="form-control"
                                    name="proCode"></select>
                        </div>
                    </div>
                    <div class="form-group" id="KK" >
                        <label class="col-sm-3 control-label no-padding-right">项目编号 ：</label>
                        <div class="col-sm-9">
                            <input class="form-control" name="proCode" id="sheetForm-Code" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">项目名称 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="proName" id="sheetForm-proName" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">项目数量 ：</label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" name="proNum" id="sheetForm-proNum" readonly>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">类型 ：</label>
                        <div class="col-sm-9">
                            <select id="query-malType" class="form-control" name="specialId">
                                <option value="" selected>请选择</option>
                                <option th:each="type : ${specialId}" th:value="${type.id}"
                                        th:text="${type.name}"></option>
                            </select>
                            <input name="special" id="specialName" type="hidden">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">部分 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="part" id="sheetForm-part">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">总图号 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="generalDrawingNo"
                                   id="sheetForm-generalDrawingNo">
                        </div>
                    </div>
                    <input type="hidden" class="form-control" name="proId" id="proId">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="saveMaintain()" id="btn-add"  shiro:hasPermission="tec:proProduc:edit">
                    提交
                </button>
                <button type="button" class="btn btn-primary" onclick="editMaintain()" id="btn-edit"  shiro:hasPermission="tec:proProduc:edit">
                    修改
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div th:include="include :: footer"></div>
<script th:inline="javascript">


    /** * 用户模态框 */
    function openReleaseModal() {
        document.getElementById("partForm").reset();
        $("#KK").hide();
        $("#DD").show();
        // document.getElementById('DD').style.visibility = "visible";
        // document.getElementById('KK').style.visibility = "hidden";
        document.all("KK").style.display="none";
        $("#btn-edit").hide();
        $("#btn-add").show();
        js.modal.open("myModal");

    }

    /**保存模态框*/
    function saveMaintain() {
        let res = js.vd({
            id: 'partForm',
            notEmpty: ['proCode', 'part', 'specialId', 'generalDrawingNo']
        })
        if (!res) {
            return;
        }
        $("#specialName").val($("#query-malType option:selected").text());
        var url = ctx + "craft/productionInput/add/Production";
        js.validSubmit({
            formId: "partForm",
            url: url,
            data: new FormData($("#partForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("myModal");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });

    }
    /**保存模态框*/
    function editMaintain() {
        let res = js.vd({
            id: 'partForm',
            notEmpty: [ 'part', 'specialId', 'generalDrawingNo']
        })
        if (!res) {
            return;
        }
        $("#specialName").val($("#query-malType option:selected").text());
        var url = ctx + "craft/productionInput/edit/Production";
        js.validSubmit({
            formId: "partForm",
            url: url,
            data: new FormData($("#partForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("myModal");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });

    }
    let table;


    function updateProduction(part, generalDrawingNo, proCode, id, specialId, special,proNum,proName) {

        $("#sheetForm-Code").val(proCode);
        $("#sheetForm-proNum").val(proNum);
        $("#sheetForm-proName").val(proName);
        $("#sheetForm-part").val(part);
        $("#query-malType option:selected").val(specialId);
        $("#query-malType option:selected").text(special);
        $("#specialName option:selected").val(special);
        $("#sheetForm-generalDrawingNo").val(generalDrawingNo);
        $("#id").val(id);
        $("#DD").hide();
        $("#KK").show();
        // document.getElementById('DD').style.visibility = "hidden";
        // document.getElementById('KK').style.visibility = "visible";
        document.all("DD").style.display="none";
        $("#btn-edit").show();
        $("#btn-add").hide();
        js.modal.open("myModal");
    }
    /** 删除数据 */
    function del(id) {
        js.modal.confirm("确认删除吗？", function () {
            js.post({
                url: ctx + "craft/productionInput/del",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.alert("工艺员已经创建工艺卡，请联系工艺员删除工艺卡后再删除此单据！！");
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }
    $(function () {

        /** 项目编号下拉框 */
        js.select2({
            id: 'sheetForm-proCode',
            placeholder: '',
            ajax: {

                url: function () {
                    return ctx + 'craft/productionInput/project/list'
                },
                processResults: function (data, page) {

                    let array = data;
                    for (let i = 0; i < data.length; i++) {
                        array[i]["proId"] = array[i]['id'];
                        array[i]["id"] = array[i]['code'];
                        array[i]["text"] = array[i]['code'];

                    }
                    return {results: array};
                },
            }
        });
        /** 项目编号下拉框选中 */
        $("#sheetForm-proCode").on("select2:select", function () {
            $("#sheetForm-proName").val($(this).select2("data")[0].name);
            $("#sheetForm-proNum").val($(this).select2("data")[0].num);
            $("#proId").val($(this).select2("data")[0].proId);
            $("#sheetForm-proCode").val($(this).select2("data")[0].code);
        });


        /** 加载列表 */
        table = js.table.init({
            url: ctx + "craft/productionInput/list",
            showExport: false,
            columns: [
                {

                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "项目编号", field: 'proCode'},
                {title: "项目名称", field: 'proName'},
                {title: "项目数量", field: 'proNum'},
                {title: "类型", field: 'special'},
                {title: "部分", field: 'part'},
                {title: "总图号", field: 'generalDrawingNo'},
                // {title: "创建科室", field: 'sectionName'},
                // {title: "创建者", field: 'createNameTwo'},
                {title: "创建时间", field: 'verifyTime'},
                {
                    title: "操作",
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="' + ctx + 'craft/productionInput/info/' + row.id + '"> 查看</a> ');
                        // actions.push('<a class="btn btn-warning btn-xs"  onclick=updateProduction('+row.id+','+row.proName+','+row.proNum+','+row.proCode+','+row.part+','+row.specialId+','+row.generalDrawingNo+')> 修改</a> ');
                        actions.push('<a class="btn btn-warning btn-xs"  shiro:hasPermission="tec:proProduc:edit" onclick=updateProduction(&quot;' + row.part + '&quot;,&quot;' + row.generalDrawingNo + '&quot;,&quot;' + row.proCode + '&quot;,&quot;' + row.id + '&quot;,&quot;' + row.specialId + '&quot;,&quot;' + row.special + '&quot;,&quot;' + row.proNum + '&quot;,&quot;' + row.proName + '&quot;)> 修改</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" shiro:hasPermission="tec:proProduc:del" onclick="del(' + row.id + ')" > 删除</a> ');
                        return actions.join('');
                    }
                }
            ]
        });


    });
</script>
</body>
</html>
